#coding=utf-8
#import libs 
import sys
import os
from   os.path import abspath, dirname
sys.path.insert(0,abspath(dirname(__file__)))
import Project1_cmd
import Project1_sty
import Fun
import EXUIControl
EXUIControl.FunLib = Fun
EXUIControl.G_ExeDir = Fun.G_ExeDir
EXUIControl.G_ResDir = Fun.G_ResDir
import tkinter
from   tkinter import *
import tkinter.ttk
import tkinter.font
from   PIL import Image,ImageTk

#Add your Varial Here: (Keep This Line of comments)
#Define UI Class
class  Project1:
    def __init__(self,root,isTKroot = True,params=None):
        uiName = Fun.GetUIName(root,self.__class__.__name__)
        self.uiName = uiName
        Fun.Register(uiName,'UIClass',self)
        self.root = root
        self.isTKroot = isTKroot
        self.firstRun = True
        Fun.G_UIParamsDictionary[uiName]=params
        Fun.G_UICommandDictionary[uiName]=Project1_cmd
        Fun.Register(uiName,'root',root)
        style = Project1_sty.SetupStyle(isTKroot)
        if isTKroot == True:
            Fun.SetTitleBar(root,titleText='模拟器0.9',isDarkMode=False)
            Fun.CenterDlg(uiName,root,2079,929)
            Fun.WindowDraggable(root,False,0,'#ffffff')
            root['background'] = '#EFEFEF'
        Form_1= tkinter.Canvas(root,width = 10,height = 4)
        Form_1.pack(side=tkinter.TOP,fill=tkinter.BOTH,expand=True)
        Form_1.configure(width = 2079)
        Form_1.configure(height = 929)
        Form_1.configure(bg = "#EFEFEF")
        Form_1.configure(highlightthickness = 0)
        Fun.Register(uiName,'Form_1',Form_1)
        Fun.SetUIRootSize(uiName,2079,929)
        Group_1_Variable = Fun.AddTKVariable(uiName,'Group_1')
        Group_1_Variable.set(1)
        #Create the elements of root 
        Frame_4 = tkinter.Frame(Form_1)
        Fun.Register(uiName,'PyMe_Frame_4',Frame_4,'Frame_1')
        Fun.SetControlPlace(uiName,'PyMe_Frame_4',47,47,942,78,'nw',True,True)
        Frame_4.configure(bg = "#CCCCCC")
        Label_6 = tkinter.Label(Frame_4,text="服务器")
        Fun.Register(uiName,'PyMe_Label_6',Label_6,'Label_1')
        Fun.SetControlPlace(uiName,'PyMe_Label_6',41,15,100,48,'nw',True,True)
        Label_6.configure(bg = "#EFEFEF")
        Label_6.configure(fg = "SystemButtonText")
        Label_14 = tkinter.Label(Frame_4,text="已连接")
        Fun.Register(uiName,'PyMe_Label_14',Label_14,'Label_2')
        Fun.SetControlPlace(uiName,'PyMe_Label_14',638,15,100,48,'nw',True,True)
        Label_14.configure(bg = "SystemButtonFace")
        Label_14.configure(fg = "SystemButtonText")
        Label_22 = tkinter.Label(Frame_4,text="连接断开")
        Fun.Register(uiName,'PyMe_Label_22',Label_22,'Label_5')
        Fun.SetControlPlace(uiName,'PyMe_Label_22',794,15,100,48,'nw',True,True)
        Label_22.configure(bg = "SystemButtonFace")
        Label_22.configure(fg = "#DA4453")
        Entry_7= EXUIControl.CustomEntry(Frame_4)
        Fun.Register(uiName,'PyMe_Entry_7',Entry_7,'Entry_1')
        Entry_7.SetBGColor("#FFFFFF")
        Entry_7.SetBGColor_ReadOnly("#EFEFEF")
        Entry_7.SetFGColor("#000000")
        Entry_7.SetTipFGColor("#888888")
        Entry_7.SetRelief("sunken")
        Fun.SetControlPlace(uiName,'PyMe_Entry_7',161,15,240,48,'nw',True,True)
        Button_8 = tkinter.Button(Frame_4,text="连接")
        Fun.Register(uiName,'PyMe_Button_8',Button_8,'Button_1')
        Fun.SetControlPlace(uiName,'PyMe_Button_8',426,15,120,48,'nw',True,True)
        Button_8.configure(bg = "#EFEFEF")
        Button_8.configure(fg = "#000000")
        Button_8.configure(command=lambda:Fun.CommandFunction_Adaptor(Project1_cmd.Button_1_onCommand,uiName,"Button_1"))
        Frame_43 = tkinter.Frame(Form_1)
        Fun.Register(uiName,'PyMe_Frame_43',Frame_43,'Frame_2')
        Fun.SetControlPlace(uiName,'PyMe_Frame_43',47,151,600,760,'nw',True,True)
        Frame_43.configure(bg = "#CCCCCC")
        Fun.SetElementLayer(uiName,'Frame_2',direction='lower')
        Button_40 = tkinter.Button(Frame_43,text="添加")
        Fun.Register(uiName,'PyMe_Button_40',Button_40,'Button_2')
        Fun.SetControlPlace(uiName,'PyMe_Button_40',53,12,120,48,'nw',True,True)
        Button_40.configure(bg = "#EFEFEF")
        Button_40.configure(fg = "#000000")
        Button_40.configure(command=lambda:Fun.CommandFunction_Adaptor(Project1_cmd.Button_2_onCommand,uiName,"Button_2"))
        Fun.SetElementLayer(uiName,'Button_2',direction='lift')
        Button_41 = tkinter.Button(Frame_43,text="清除")
        Fun.Register(uiName,'PyMe_Button_41',Button_41,'Button_3')
        Fun.SetControlPlace(uiName,'PyMe_Button_41',226,12,120,48,'nw',True,True)
        Button_41.configure(bg = "#EFEFEF")
        Button_41.configure(fg = "#000000")
        Button_41.configure(command=lambda:Fun.CommandFunction_Adaptor(Project1_cmd.Button_3_onCommand,uiName,"Button_3"))
        Fun.SetElementLayer(uiName,'Button_3',direction='lift')
        NoteBook_42 = tkinter.ttk.Notebook(Frame_43)
        Fun.Register(uiName,'PyMe_NoteBook_42',NoteBook_42,'NoteBook_1')
        Fun.SetControlPlace(uiName,'PyMe_NoteBook_42',36,69,527,680,'nw',True,True)
        style.map("NoteBook_1.TNotebook.Tab", background=[("selected", '#DA4453')], foreground=[("selected", '#FFFFFF')])
        NoteBook_42.configure(style ="NoteBook_1.TNotebook")
        Button_47 = tkinter.Button(Form_1,text="模拟")
        Fun.Register(uiName,'PyMe_Button_47',Button_47,'Button_4')
        Fun.SetControlPlace(uiName,'PyMe_Button_47',1446,61,155,61,'nw',True,True)
        Button_47.configure(bg = "#EFEFEF")
        Button_47.configure(fg = "#000000")
        Button_47.configure(activebackground = "#DA4453")
        Button_47.configure(activeforeground = "#FFFFFF")
        Button_47.configure(command=lambda:Fun.CommandFunction_Adaptor(Project1_cmd.Button_4_onCommand,uiName,"Button_4"))
        Button_48 = tkinter.Button(Form_1,text="Console")
        Fun.Register(uiName,'PyMe_Button_48',Button_48,'Button_5')
        Fun.SetControlPlace(uiName,'PyMe_Button_48',1679,61,155,61,'nw',True,True)
        Button_48.configure(bg = "#EFEFEF")
        Button_48.configure(fg = "#000000")
        Button_48.configure(activebackground = "#DA4453")
        Button_48.configure(activeforeground = "#FFFFFF")
        Button_48.configure(command=lambda:Fun.CommandFunction_Adaptor(Project1_cmd.Button_5_onCommand,uiName,"Button_5"))
        Button_53 = tkinter.Button(Form_1,text="地图")
        Fun.Register(uiName,'PyMe_Button_53',Button_53,'Button_6')
        Fun.SetControlPlace(uiName,'PyMe_Button_53',1198,61,168,61,'nw',True,True)
        Button_53.configure(bg = "#EFEFEF")
        Button_53.configure(fg = "#000000")
        Button_53.configure(command=lambda:Fun.CommandFunction_Adaptor(Project1_cmd.Button_6_onCommand,uiName,"Button_6"))
        Frame_51 = tkinter.Frame(Form_1)
        Fun.Register(uiName,'PyMe_Frame_51',Frame_51,'Frame_3')
        Fun.SetControlPlace(uiName,'PyMe_Frame_51',49,151,1979,753,'nw',False,True)#lock
        Frame_51.place_forget()
        Frame_51.configure(bg = "#CCCCCC")
        Fun.SetElementLayer(uiName,'Frame_3',direction='lower')
        Frame_52 = tkinter.Frame(Form_1)
        Fun.Register(uiName,'PyMe_Frame_52',Frame_52,'Frame_4')
        Fun.SetControlPlace(uiName,'PyMe_Frame_52',670,148,1358,765,'nw',True,True)#lock
        Frame_52.configure(bg = "#CCCCCC")
        #Inital all element's Data 
        Fun.InitElementData(uiName)
        #Add Some Logic Code Here: (Keep This Line of comments)



        #Exit Application: (Keep This Line of comments)
        if self.isTKroot == True and Fun.GetElement(self.uiName,"root"):
            self.root.protocol('WM_DELETE_WINDOW', self.Exit)
            self.root.bind('<Configure>', self.Configure)
            
    def GetRootSize(self):
        return Fun.GetUIRootSize(self.uiName)
    def GetAllElement(self):
        return Fun.G_UIElementDictionary[self.uiName]
    def Escape(self,event):
        if Fun.AskBox('提示','确定退出程序？') == True:
            self.Exit()
    def Exit(self):
        if self.isTKroot == True:
            Fun.DestroyUI(self.uiName)

    def Configure(self,event):
        Form_1 = Fun.GetElement(self.uiName,'Form_1')
        if Form_1 == event.widget:
            Fun.ReDrawCanvasRecord(self.uiName)
        if self.root == event.widget:
            Fun.ResizeRoot(self.uiName,self.root,event)
            Fun.ResizeAllChart(self.uiName)
            uiName = self.uiName
            pass
        Fun.ActiveElement(self.uiName,event.widget)
#Create the root of Kinter 
if  __name__ == '__main__':
    Fun.RunApplication(Project1)
